import type { PromiseType } from '#types/utils'

import { ref } from 'vue'

import { message } from 'ant-design-vue'

import SysUserApi from '#/api/system/user'
import { $t } from '@vben/locales'

type TableList = PromiseType<ReturnType<typeof SysUserApi.inst.getPageList>>['records']
export type TableListItem = TableList[number]

/**
 * 重置密码
 */
export function useResetPsw(psw = '123456') {
    const defaultPsw = ref(psw)

    async function reset(record: TableListItem) {
        await SysUserApi.inst.resetPwd({
            id: record.id,
            password: defaultPsw.value
        })

        message.success($t('components.EditPassword.children.resetSuccess'))
    }

    return {
        defaultPsw,
        reset
    }
}
